function [ actors ] = buildLocalNetworkY( actor1, actor2, X )

% Takes two actor indices (actor1 and actor2) and a matrix of relationships
% (X) between all network actors;
% Returns an index list of actors (actors) that influence the emergence of
% a knowledge tie ( actor1, actor2 ), i.e. actor1 gets to know actor2 
% This is everybody in the first and second circles of actor1

[ ~, len ] = size( X ); 

actors = zeros( 0, 1 );

circle1 = zeros( 0, 1 );
for i = 1 : len
    if i == actor1
        circle1 = [ circle1; i ];
    elseif ( X( i, actor1 ) == 1 )
        circle1 = [ circle1; i ];
    end
end

if isempty( circle1 )
    return
end

actor2incircle2 = 0;

[ circle1size, ~ ] = size( circle1 );
for i = 1 : len
    for nextfriend = 1 : circle1size
        if ( i == circle1( nextfriend ) ) || ( X( i, circle1( nextfriend ) ) == 1 )
            actors = [ actors; i ];
            if i == actor2
                actor2incircle2 = 1;
            end
            break
        end
    end
end

if actor2incircle2 == 0
    actors = zeros( 0, 1 );
end
